<?php

$error=array();
if(empty($_POST)==false){
$username=  isset($_POST['username'])?trim($_POST['username']):'';
$password=  isset($_POST['password'])?trim($_POST['password']):'';
        //echo $username;
        //echo $password;
        //exit;
require( 'db.php');
$sql="select * from tb_user where username='$username'";
$result=$db->query($sql);
$sum=$result->num_rows;
    if($sum>0){
        $row=$result->fetch_array();
        if($row['password']==$password){
        session_start();
        $_SESSION['userinfo']=array('uid'=>$row['uid'],'username'=>$row['username']);
        header('Location:index.php');
        die;
        }
 else { $error[]="密码错误！";}
    }
 else {
        $error[]="用户名不存在！";
    }
}
require ('dengru_index.php');

